import java.util.ArrayList;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:有重复项数字的全排列
 * User: wangxin
 * Date: 2024-12-24
 * Time: 21:53
 */
public class Test1 {
    public void permuteUniqueRC(ArrayList<Integer> nums, ArrayList<Integer> perm){
        if(nums.isEmpty()){
            ArrayList<Integer> a = new ArrayList<Integer>(perm);
            if(!res.contains(a))
                res.add(a);
            return;
        }
        for(int i = 0; i < nums.size();i++){
            Integer a = nums.remove(i);
            perm.add(a);
            permuteUniqueRC(nums,perm);
            nums.add(i,a);
            perm.remove(perm.size()-1);
        }

    }
    ArrayList<ArrayList<Integer>> res = new ArrayList<ArrayList<Integer>> ();
    public ArrayList<ArrayList<Integer>> permuteUnique (int[] num) {
        // write code here
        Arrays.sort(num);
        ArrayList<Integer> nums = new ArrayList<Integer>();
        for(int i = 0;i < num.length;i++)
            nums.add(num[i]);

        permuteUniqueRC(nums,new ArrayList<Integer>());
        return res;
    }
}
